/**
 * Copyright (c) 2012-2013 YunZhiSheng(Shanghai) Co.Ltd. All right reserved.
 * @FileName : BaiduMap.java
 * @ProjectName : vui_assistant
 * @PakageName : cn.yunzhisheng.vui.assistant.baidu
 * @Author : Dancindream
 * @CreateDate : 2013-9-6
 */
package cn.yunzhisheng.vui.assistant.baidu;

import cn.yunzhisheng.common.util.LogUtil;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;

/**
 * @Module : 隶属模块名
 * @Comments : 描述
 * @Author : Dancindream
 * @CreateDate : 2013-9-6
 * @ModifiedBy : Dancindream
 * @ModifiedDate: 2013-9-6
 * @Modified:
 * 2013-9-6: 实现基本功能
 */
public class BaiduMap {
	public static final String TAG = "BaiduMap";
	public static final String ROUTE_MODE_WALKING = "walking"; // 步行
	public static final String ROUTE_MODE_DRIVING = "driving"; // 驾车
	public static final String ROUTE_MODE_TRANSIT = "transit"; // 公交
	private static boolean mHasBaiduMapClient = false;

	public static void init(Context context) {
		mHasBaiduMapClient = hasBaiduMapClient(context);
	}

	private static boolean hasBaiduMapClient(Context context) {
		PackageInfo packageInfo;
		try {
			packageInfo = context.getPackageManager().getPackageInfo("com.baidu.BaiduMap", 0);
		} catch (NameNotFoundException e) {
			packageInfo = null;
		}
		if (packageInfo == null) {
			return false;
		} else {
			return true;
		}
	}

	public static void showLocation(Context context, String title, String content, String lat, String lng) {
		if (context == null) {
			return;
		}

		mHasBaiduMapClient = hasBaiduMapClient(context);
		if (mHasBaiduMapClient) {
			BaiduUriApi.showLocation(context, title, content, lat, lng);
		} else {
			BaiduMapSdk.showLocation(context, title, content, lat, lng);
		}
	}

	public static void showRoute(Context context, String mode, double fromLat, double fromLng, String fromCity,
									String fromPoi, double toLat, double toLng, String toCity, String toPoi) {
		if (context == null) {
			LogUtil.e(TAG, "showRoute:context null!");
			return;
		}

		mHasBaiduMapClient = hasBaiduMapClient(context);
		if (mHasBaiduMapClient) {
			BaiduUriApi.showRoute(context, mode, fromLat, fromLng, fromCity, fromPoi, toLat, toLng, toCity, toPoi);
		} else {
			BaiduMapSdk.showRoute(context, mode, fromLat, fromLng, fromCity, fromPoi, toLat, toLng, toCity, toPoi);
		}
	}

}
